
<?
//=====================================================
$path = '../Mkart/';
include($path."common.php");
include($path."prod_fun.php");
//=====================================================
$_POST = str_replace("'","",$_POST) ;
$_POST = str_replace("//","////",$_POST) ;

if($_POST['consigenee_check'] == "Y"){
$consignee_name = $_POST['shopper_name'] ;
$consignee_tel = $_POST['shopper_tel'] ;
$consignee_phone = $_POST['shopper_phone'] ;
$consignee_zip = $_POST['shopper_zip'] ;
$consignee_address = $_POST['shopper_address'] ;
$consignee_mail = $_POST['shopper_mail'] ;
}else{
$consignee_name = $_POST['consignee_name'] ;
$consignee_tel = $_POST['consignee_tel'] ;
$consignee_phone = $_POST['consignee_phone'] ;
$consignee_zip = $_POST['consignee_zip'] ;
$consignee_address = $_POST['consignee_address'] ;
$consignee_mail = $_POST['consignee_mail'] ;
}


$shopper_name = $_POST['shopper_name'] ;
$shopper_tel = $_POST['shopper_tel'] ;
$shopper_phone = $_POST['shopper_phone'] ;
$shopper_zip = $_POST['shopper_zip'] ;
$shopper_address = $_POST['shopper_address'] ;
$shopper_mail = $_POST['shopper_mail'] ;

$type = $_POST['type'] ;
$amount = $_POST['amount'];
$stage = $_POST['stage'];
$invoice = $_POST['invoice'];
$invoice_no = $_POST['invoice_no'];



if(empty($shopper_name) or empty($shopper_phone) or empty($shopper_address) or empty($consignee_name) or empty($consignee_phone) or empty($consignee_address) or empty($stage)){
$data_num = 0  ;
//$data_num = $shopper_name ;
}else{
$sql_num = "select * from kart_order order by order_id desc limit 1 " ;
$result_num = mysql_query($sql_num) ;
$row_num=mysql_fetch_object($result_num) ;
$num = $row_num->order_id ;
if(empty($num)){
$data_num = "OD00000001" ;
}else{
$data_num = (substr($num, 0,2) . substr((100000000 + substr($num , 2,8) + 1) , 1 ,8)) ;
}
//============================================
$sql_add_order = "insert into kart_order set 
					order_id = '$data_num' , 
					order_type = '$type' , 
					order_price = '$amount' , 
					order_state = 'N' , 
					order_date = '' , 
					order_time = '' , 
					order_auth = '' ,
					order_stage = '$stage' ,
					order_invoice = '$invoice' , 
					order_invoiceno = '$invoice_no' 
					" ;
$result_add_order = mysql_query($sql_add_order) ;
//echo $sql_add_order ;
//============================================
$p_list = explode(",",$_POST['item_list']) ;
$p_list_sum = explode(",",$_POST['item_list_sum']) ;

for($n=0 ;$n<count($p_list) ; $n++){
$sql_add_list = "insert into order_item set 
					order_id = '$data_num' , 
					item_id = '$p_list[$n]' , 
					item_amount = '$p_list_sum[$n]'
					" ;
$result_add_list = mysql_query($sql_add_list) ;

}
//============================================
$sql_add_shopper = "insert into order_shopper set 
					order_id = '$data_num' , 
					shopper_name = '$shopper_name' , 
					shopper_tel = '$shopper_tel' , 
					shopper_cellphone = '$shopper_phone' , 
					shopper_zip = '$shopper_zip' , 
					shopper_address = '$shopper_address' , 
					shopper_mail = '$shopper_mail' 
					" ;
$result_add_shopper = mysql_query($sql_add_shopper) ;
//============================================
$sql_add_consignee = "insert into order_consignee set 
					order_id = '$data_num' , 
					consignee_name = '$consignee_name' , 
					consignee_tel = '$consignee_tel' , 
					consignee_cellphone = '$consignee_phone' , 
					consignee_zip = '$consignee_zip' , 
					consignee_address = '$consignee_address' , 
					consignee_mail = '$consignee_mail' 
					" ;
$result_add_consignee = mysql_query($sql_add_consignee) ;
//============================================
$res = array('num' => $data_num);	

}
echo $data_num ;
?>